package com.fhzn.boss.entity;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @author fhzn
 */
@Accessors(chain = true)
@Data
public class TagType {

    public static final String PLATFORM_DICT_TYPE = "platform-type-list";
    public static final String BUILT_IN_DICT_TYPE = "built-in-type-list";

    private Integer id;

    private String type;

    private String code;

    private String name;

    private int sort;

    private String comment;

    private boolean ifHidden;

    private String creator;

    private String modifier;

    private Date createdTime;

    private Date updatedTime;

    private String appCode;

    public static TagType fromTag(Tag tag) {
        return new TagType().setId(tag.getId())
                .setType(tag.getType())
                .setCode(tag.getCode())
                .setAppCode(tag.getAppCode())
                .setName(tag.getName())
                .setSort(tag.getSort())
                .setComment(tag.getComment())
                .setIfHidden(tag.getIfHidden())
                .setCreator(tag.getCreator())
                .setCreatedTime(tag.getCreatedTime())
                .setModifier(tag.getModifier())
                .setUpdatedTime(tag.getUpdatedTime());
    }

    public Tag toTag() {
        Tag tag = new Tag().setId(getId())
                .setName(getType())
                .setParentId(0)
                .setType("")
                .setIfHidden(ifHidden)
                .setSort(sort)
                .setComment(getComment())
                .setExtension(new TagExtension())
                .setIfDeleted(false);
        tag.setModifier(getModifier());
        tag.setCreator(getCreator());
        tag.setCreatedTime(getCreatedTime());
        tag.setUpdatedTime(getUpdatedTime());
        return tag;
    }

    public Tag toTagType(TagType type) {
        Tag tag = new Tag();
        tag.setId(type.getId())
                .setName(type.getName())
                .setCode(type.getCode())
                .setParentId(0)
                .setType(PLATFORM_DICT_TYPE)
                .setAppCode(type.getAppCode())
                .setExtension(new TagExtension())
                .setComment(type.getComment());
        return tag;
    }
}
